<?php

class FirmtmplsController extends AdminController {

	public function getListTrialTime() {
		return array(
			'1' => AdminModule::t('1 день'),
			'10' => AdminModule::t('10 дней'),
			'15' => AdminModule::t('15 дней'),
			'20' => AdminModule::t('20 дней'),
			'30' => AdminModule::t('1 месяц'),
			'90' => AdminModule::t('3 месяца'),
		);
	}

	public function getListLifeTime() {
		return array(
			'0' => AdminModule::t('нет'),
			'90' => AdminModule::t('3 месяца'),
			'180' => AdminModule::t('6 месяцев'),
			'365' => AdminModule::t('1 год'),
		);
	}
	
	public function actionView($id) {
		$this->render('view', array(
			'model' => $this->loadModel($id, 'FirmTmpls'),
		));
	}

	public function actionCreate() {
		$model = new FirmTmpls;


		if (isset($_POST['FirmTmpls'])) {
			$model->setAttributes($_POST['FirmTmpls']);

			if ($model->save()) {
				if (Yii::app()->getRequest()->getIsAjaxRequest())
					Yii::app()->end();
				else
					$this->redirect(array('view', 'id' => $model->id));
			}
		}

		$this->render('create', array( 'model' => $model));
	}

	public function actionUpdate($id) {
		$model = $this->loadModel($id, 'FirmTmpls');


		if (isset($_POST['FirmTmpls'])) {
			$model->setAttributes($_POST['FirmTmpls']);

			if ($model->save()) {
				$this->redirect(array('view', 'id' => $model->id));
			}
		}

		$this->render('update', array(
				'model' => $model,
				));
	}

	public function actionDelete($id) {
		if (Yii::app()->getRequest()->getIsPostRequest()) {
			$this->loadModel($id, 'FirmTmpls')->delete();

			if (!Yii::app()->getRequest()->getIsAjaxRequest())
				$this->redirect(array('admin'));
		} else
			throw new CHttpException(400, AdminModule::t('Некорректный запрос.'));
	}

	public function actionIndex() {
		$dataProvider = new CActiveDataProvider('FirmTmpls');
		$this->render('index', array(
			'dataProvider' => $dataProvider,
		));
	}

	public function actionAdmin() {
		$model = new FirmTmpls('search');
		$model->unsetAttributes();

		if (isset($_GET['FirmTmpls']))
			$model->setAttributes($_GET['FirmTmpls']);

		$this->render('admin', array(
			'model' => $model,
		));
	}

}